package com.cqie.controller.entrepot;

import com.cqie.dto.entrepot.AddEntrepotDrugInfoDto;
import com.cqie.dto.entrepot.EntrepotDrugInfoListDto;
import com.cqie.exception.SpecialException;
import com.cqie.service.IEntrepotDrugInfoService;
import com.cqie.util.ResultTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库药品信息 前端控制器
 * </p>
 *
 * @author 不吃海鲜
 * @since 2024-12-19
 */
@Tag(name = "仓库药品信息Controller", description = "描述：仓库药品信息接口")
@RestController
@RequestMapping({"/api/v1.0/entrepotDrugInfo", "/api/v1/entrepotDrugInfo"})
public class EntrepotDrugInfoController {

    private final IEntrepotDrugInfoService entrepotDrugInfoService;

    public EntrepotDrugInfoController(IEntrepotDrugInfoService entrepotDrugInfoService) {
        this.entrepotDrugInfoService = entrepotDrugInfoService;
    }

    @Operation(summary = "新增仓库药品信息(进货)")
    @PostMapping("/addEntrepotDrugInfo")
    public ResultTemplate<Boolean> saveEntrepotDrugInfo(@RequestBody AddEntrepotDrugInfoDto addEntrepotDrugInfoDto) throws SpecialException {
        return ResultTemplate.Success(entrepotDrugInfoService.saveEntrepotDrugInfo(addEntrepotDrugInfoDto));
    }

    @Operation(summary = "根据仓库id查询仓库药品信息列表")
    @Parameters({
            @Parameter(name = "warehouseId", description = "仓库id")
    })
    @GetMapping("/getEntrepotDrugInfoByWarehouseIdList")
    public ResultTemplate<List<EntrepotDrugInfoListDto>> getEntrepotDrugInfoByWarehouseIdList(
            Integer warehouseId,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer pageIndex) throws SpecialException {
        return ResultTemplate.Success(entrepotDrugInfoService.getEntrepotDrugInfoByWarehouseIdList(warehouseId,
                pageSize, pageIndex));
    }

    @Operation(summary = "根据仓库id查询仓库药品信息列表的数量")
    @Parameters({
            @Parameter(name = "warehouseId", description = "仓库id")
    })
    @GetMapping("/getEntrepotDrugInfoByWarehouseIdCount")
    public ResultTemplate<Long> getEntrepotDrugInfoByWarehouseIdCount(Integer warehouseId) throws SpecialException {
        return ResultTemplate.Success(entrepotDrugInfoService.getEntrepotDrugInfoByWarehouseIdList(warehouseId, 9999,
                1).size());
    }

}
